home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BBS in a Box 7
/
BBS in a Box - Macintosh - Volume VII (BBS in a Box) (January 1993).iso
/
Files
/
Prog
/
N-P
/
OOP for C.cpt
/
Flavors4C.ƒ
/
Flavor4C.h
next >
Wrap
Text File
|
1988-11-30
|
10KB
|
371 lines
/****************************************************************************/
/* Flavors4C, an object oriented library in C, Version 1.0 */
/* © Copyright 1988 Peter Ohler, All Rights Reserved */
/* 460 Monti Court */
/* Pleasant Hill, CA 94523 */
/* (415) 686-1317 */
/****************************************************************************/
/* flavor4c.h */
/*--------------------------------------------------------------------------*/
/* CFlavors is an object oriented package for C. It should work on any
C compiler that supports the K&R C standard. It is not a preprocessor
but consists of the library cflavors and the header file cflavors.h.
Some standard libraries and headers are needed to allow memory
allocation and IO. (It calls malloc(), sprintf() and printf()).
CFlavors does not adhere rigidly to the flavors found on LISP machines
since, after all this is C not LISP. It does, however, encompass most
of the concepts that LISP flavors includes and when ever possible syntax
is similar. Users familiar with LISP flavors will notice many
similarities between CFlavors and LISP flavors. This similarity should
allow an easy translation from LISP to C.
*/
/* These defines are used to keep function and variable names readable yet
smaller than 8 characters for some compilers.
*/
#define allFlavors allFlavs
#define WarningFunction cf_warn
#define error_check error_ck
#define flavor_specifier flav_spc
#define DefFlavor DefFlav
#define AbstractFlavor AbstFlav
#define RequiredVars ReqVars
#define RequiredMethods ReqMeths
#define RequiredFlavors ReqFlavs
#define IncludedFlavors IncFlavs
#define NoVanillaFlavor NoVanil
#define MethodCombination MethComb
#define DefaultHandler DefHand
#define DefMethod DefMeth
#define CompileFlavor CompFlav
#define ContinueWhopper ContWhop
#define StringToFlavor StrTFlav
#define FlavorToString FlavTStr
#define MakeInstance MakeInst
#define BroadCast BroadCst
/* These are the public types. It is left up to the user to keep track of
each structure.
*/
typedef struct flavor Flavor;
typedef struct instance Instance;
typedef char *Pntr;
/*
allFlavors is a NULL terminated array of all the defined flavors.
*/
extern Flavor **allFlavors;
/*
WarningFunction is a pointer to the function used to display warning
messages. It can be reset to point to some user defined function at the
user's discretion. It takes a single argument which is a string.
*/
extern int (*WarningFunction)();
/*
error_check is a flag which enables the error checking during execution.
Once the code is tested some performance improvement can be realized by
setting it to 0 and disabling some of the error checks.
*/
extern int error_check;
/*
flavor_specifier is a flag used to indicate how CFlavors reads flavor
arguments in many functions.
*/
extern int flavor_specifier;
#define STR_SPECIFY 0x01
#define Pntr_SPECIFY 0x02
extern int flavor_specifier; /* default is (STR_SPECIFY | Pntr_SPECIFY) */
#define NOT_DEFINED 0x00
#define DAEMON 0x01
#define OR_COMB 0x02
#define AND_COMB 0x03
#define DAEMON_OR 0x04
#define DAEMON_AND 0x05
#define PROGN 0x06
#define BASE_FLAVOR_LAST 0x00
#define BASE_FLAVOR_FIRST 0x10
#define PRIMARY 0x01
#define BEFORE 0x02
#define AFTER 0x04
#define AROUND WHOPPER
#define WHOPPER 0x08
#define GETTABLE 0x01
#define SETTABLE 0x02
#define ALL 0xFF
#define INIT NULL
#define NO_INIT 0x01
/*
Flavor*
DefFlavor(name, parents)
char *name;
Pntr parents;
DefFlavor is used to define or create a Flavor (Class). After the basic
Flavor has been created the Variables, and Methods can be added to it.
The first argument to DefFlavor is a string and the second argument
(parents) is a NULL terminated array of the parent flavors or a string
composed of the the names of the parent flavors separated by white space.
*/
extern Flavor *DefFlavor();
/*
void
AbstractFlavor(flavor)
Pntr flavor;
AbstractFlavor() indicates that the flavor will not be used to create an
instance. The flavor can only be used as a mixin with other flavors.
An error occurs if an attempt is made to create an instance of this
flavor.
*/
extern void AbstractFlavor();
/*
void
RequiredVars(flavor, varNames)
Pntr flavor;
char *varNames;
*/
extern void RequiredVars();
/*
void
RequiredMethods(flavor, methods)
Pntr flavor;
char *methods;
*/
extern void RequiredMethods();
/*
void
RequiredFlavors(flavor, required)
Pntr flavor;
Pntr required;
*/
extern void RequiredFlavors();
/*
void
IncludedFlavors(flavor, included)
Pntr flavor;
Pntr included;
*/
extern void IncludedFlavors();
/*
void
NoVanillaFlavor(flavor)
Pntr flavor;
*/
extern void NoVanillaFlavor();
/*
void
MethodCombination(flavor, type, order, methods)
Pntr flavor;
int type, order;
char *methods;
*/
extern void MethodCombination();
/*
void
DefaultHandler(flavor, function)
Pntr flavor;
Pntr (*function)();
*/
extern void DefaultHandler();
/*
void
DefMethod(flavor, type, name, function)
Pntr flavor;
char type, *name;
Pntr (*function)();
*/
extern void DefMethod();
/*
Pntr
AddInstanceVar(flavor, name, flags, type, initValue)
Pntr flavor;
char *name;
int flags;
.... type, initValue;
AddInstanceVar() is used to add instance variables to a Flavor before
the flavor is compiled. The flavor argument must be a pointer to a
flavor or a flavor name. The name must be a string which is the name
of the variable. The flags argument must be a logical OR
combination of GETTABLE, SETTABLE, or ALL. The type and initValue
should match and can be any type that the compiler supports.
*/
#define AddInstanceVar(flavor, name, flags, type, initValue) \
*((type*)addIVar(flavor, name, flags, sizeof(type))) = (initValue)
extern Pntr addIVar();
/*
Pntr
AddClassVar(flavor, name, flags, type, initValue)
Pntr flavor;
char *name;
int flags;
.... type, initValue;
AddClassVar() is used to add class variables to a Flavor before the
flavor is compiled. The arguments are the same as those in
AddClassVar(). This is a nonstandard extension of flavors found only
in CFlavors.
*/
#define AddClassVar(flavor, name, flags, type, initValue) \
*((type*)addCVar(flavor, name, flags, sizeof(type))) = (initValue)
extern Pntr addCVar();
/*
void
CompileFlavor(flavor)
Pntr flavor;
CompileFlavor() sets up the flavor so that it can be used by other
flavors. All methods, variables, required items, etc. should be complete
before calling this function. In addition instance can not be made of
flavors that have not been compiled. The argument must be a pointer to
a flavor or a flavor name.
*/
extern void CompileFlavor();
/*
Pntr
ContinueWhopper(methods, object, the_rest)
Pntr methods;
Instance* *object;
.... the_rest;
*/
extern Pntr ContinueWhopper();
/*
Flavor*
StringToFlavor(name)
char *name;
StringToFlavor() will return a pointer to the Flavor which has the same
name as the argument 'name'.
*/
extern Flavor* StringToFlavor();
/*
char*
FlavorToString(flavor)
Flavor *flavor;
*/
extern char* FlavorToString();
/*
Instance*
MakeInstance(flavor, init)
Flavor *flavor;
int init;
MakeInstance() is used to make instances of a flavor. It's first
argument must be a pointer to a flavor or a flavor name. MakeInstance()
returns a pointer to an instance of the flavor.
*/
extern Instance* MakeInstance();
/*
Pntr
Send(object, message, the_rest)
Instance *object;
char *message;
.... the_rest;
Send() is used to send messages to instances of a Flavor. The first
argument must be an instance of a flavor. The second is a string for
the method to be invoked. The last set argument (or arguments),
the_rest_of_the_arguments can be any number of additional arguments that
should be applied to the method function. The method functions must
always have self (or the instance) as it's first argument. The limit
on additional arguments is that they be one less than the compiler limit
and that the total space they take up should be less that the space
required by ten double. (usually this is 80 bytes) If the compiler
supports structures as arguments that will work as well.
*/
extern Pntr Send();
/*
Pntr
BroadCast(flavor, message, the_rest)
Flavor *flavor;
char *message;
.... the_rest;
BroadCast() is similar to Send except the message is sent to every
instance of the flavor specified. This is a nonstandard extension of
flavors found only in CFlavors.
*/
extern Pntr BroadCast();
/*
Pntr
GetVar(object, varName)
Instance *object;
char *varName;
GetVar() is used to return a pointer to the variable `name' for the
instance specified. The returned pointer is for a (char) type and should
be cast to the actual variable type before it is used. The function does
not invoke any before or after daemons.
*/
extern Pntr GetVar();